package com.leetcode.algorithm.y22.m06;

/**
 * 191. 位1的个数
 * 
 * https://leetcode.cn/problems/number-of-1-bits/
 * 
 * @author jie.deng
 *
 */
public class Question0191Solution01 {
	
    // you need to treat n as an unsigned value
	public int hammingWeight(int n) {
		int cnt = 0;
		while (n != 0) {
			n = (n & n - 1);
			cnt++;
		}
		return cnt;
	}
    
}